package com.lee.security.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.lee.security.dao.SysUsersRepository;
import com.lee.security.entity.SysRole;
import com.lee.security.entity.SysUser;

public class DefaultUserDetailsService implements UserDetailsService {

	@Autowired
	private SysUsersRepository sysUsersRepository;

	/*@Autowired
	private MessageSource messageSource;
*/
//	@Autowired
//	private UserCache userCache;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		SysUser user = this.sysUsersRepository.getByUsername(username);
		List<SysRole> roleList = this.sysUsersRepository.getSysRolesByUsername(username);
		user.setRoles(roleList);
		return user;
	}

}